package com.speedchina.doormanager;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@SpringBootApplication
public class DoorManagerApplication {

    private Logger log = LoggerFactory.getLogger(DoorManagerApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(DoorManagerApplication.class);
    }

    private static final String DATE_TIME_FORMATE = "yyyy-MM-dd HH:mm:ss";

    @Bean
    public Converter<String, Date> convertDateTime() {
        return new Converter<String, Date>() {
            @Override
            public Date convert(String source) {
                Date date = null;
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_TIME_FORMATE);
                try {
                    simpleDateFormat.parse(source);
                } catch (ParseException e) {
                    log.info("parse date failed!" + e);
                }
                return date;
            }
        };
    }


}
